package com.xutianpeng.disk.login.control;

import com.xutianpeng.disk.login.entity.MenuLevelEntity;
import com.xutianpeng.disk.login.service.LoginService;
import com.xutianpeng.disk.spring.security.UserDiskEntity;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.security.access.annotation.Secured;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class MainController {
    @Resource
    private HttpSession httpSession;

    @Resource
    private LoginService loginService;

    @RequestMapping("/")
    public String main(){
        UserDiskEntity userDiskEntity = (UserDiskEntity) SecurityContextHolder.getContext()
                .getAuthentication()
                .getPrincipal();
        httpSession.setAttribute("userUuidDisk",userDiskEntity.getUserUuid());
        httpSession.setAttribute("lang" , LocaleContextHolder.getLocale().toString());
        List<MenuLevelEntity> list = loginService.queryMenuListLevel();
        httpSession.setAttribute("menuList" ,list);

        return "login/mainPage";
    }
//    @RequestMapping("/queryMenuList")
//    @ResponseBody
//    public String queryMenuList(){
//        List<PtMenuEntity> list = loginService.queryMenuList();
//
//        return JSON.toJSONString(list);
//    }
//
//    @RequestMapping("/queryMenuListLevel")
//    @ResponseBody
//    public String queryMenuListLevel(){
//        List<MenuLevelEntity> list = loginService.queryMenuListLevel();
//
//        return JSON.toJSONString(list);
//    }


    @RequestMapping("/welcomePage")
    public String queryMenuListLevel(){
          return "login/welcomePage";
    }

    @Secured("ROLE_Test1")
    @RequestMapping("/test1")
    public String test1(){
        return "test/test1Page";
    }
    @Secured("ROLE_Test2")
    @RequestMapping("/test2")
    public String test2(){
        return "test/test2Page";
    }
}
